﻿
// 添加账号

companyid = new ObjectId()

var id = companyid.valueOf()

var doc = db.school.findOne({name: "杭州乔支机动车驾驶培训学校"})

if (!doc) {
	db.school.insert({ _id: companyid, name: "杭州乔支机动车驾驶培训学校", created_time: new Date() })
}
else {
	id = doc._id.valueOf()
	print("#exist school:" , doc.name)
}

docm = db.member.findOne({name: "admin"})

if (!docm) {
	db.member.insert({name: "admin", password: "E10ADC3949BA59ABBE56E057F20F883E", role:"t", school: {id: id , display: "杭州乔支机动车驾驶培训学校"}, created_time: new Date() })
}
else {
	uid = docm._id.valueOf()
	print("#exist account:" , docm.name)
}

// update db

var currsor = db.place.find()

while (currsor.hasNext()) {
	var temp = currsor.next()
	//printjson(temp)

	db.place.update({_id: temp._id}, {$set: {member:{id: uid, display: docm.name}}} ) 
}


var currsor2 = db.course.find()

while (currsor2.hasNext()) {
	var temp = currsor2.next()
	//printjson(temp)

	db.course.update({_id: temp._id}, {$set: {member:{id: uid, display: docm.name}}} ) 
}
// -------------------------------


